package com.haoyi.feignapi.controller;

import com.github.pagehelper.PageInfo;
import com.haoyi.feignapi.entity.Attachment;
import com.haoyi.feignapi.entity.User;
import com.haoyi.feignapi.entity.requestBody.PartReq;
import com.haoyi.feignapi.service.EnMallService;
import com.haoyi.feignapi.service.ErpService;
import feign.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/enMall")
public class EnMallController {

    final
    EnMallService enMallService;

    public EnMallController(EnMallService enMallService) {
        this.enMallService = enMallService;
    }

    @PostMapping("/getOrder")
    public PageInfo<Map<String, Object>> getOrder(@RequestBody Map<String, Object> paramMap) {
        return enMallService.getOrder(paramMap);
    }

    @PostMapping("/getOrderParts")
    public List<Map<String, Object>> getOrderParts(@RequestBody Map<String, Object> paramMap) {
        return enMallService.getOrderParts(paramMap);
    }

    @PostMapping("/getOrderEN")
    public Object getOrderEN(@RequestParam("v2") String v2, @RequestParam("v3") String v3, @RequestParam("v4") String v4, @RequestParam("v5") String v5) {
        return enMallService.getOrderEN(v2, v3, v4, v5);
    }

    @PostMapping("/signinOverseasUser")
    public void signinOverseasUser(@RequestBody User user) {
        enMallService.signinOverseasUser(user);
    }

    @PostMapping("/getUserBySearch")
    public List<User> getUserBySearch(@RequestParam Integer permission_id, @RequestParam String search) {
        return enMallService.getUserBySearch(permission_id, search);
    }

    @PostMapping("/getUserByPermission")
    public List<User> getUserByPermission(@RequestParam Integer permission_id) {
        return enMallService.getUserByPermission(permission_id);
    }


    @PostMapping("/getAttachment")
    public Object getAttachment(@RequestBody PartReq partReq) {
        return enMallService.getAttachment(partReq);
    }


    @PostMapping("/orderProcessing")
    Map<String, Object> orderProcessing(@RequestBody Map<String, Object> paramMap) {
        return enMallService.orderProcessing(paramMap);
    }


    @PostMapping("/getUserData")
    PageInfo<Map<String, Object>> getUserData(@RequestBody Map<String, Object> paramMap){
        return enMallService.getUserData(paramMap);
    }


    @GetMapping("/getAllTradeCount")
    Integer getAllTradeCount(@RequestParam("date1") Date date1, @RequestParam("date2") Date date2){
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date11 = new Date();
        Date date22 = new Date();

        try {
             date11 = dateFormat.parse(dateFormat.format(date1));
             date22 = dateFormat.parse(dateFormat.format(date2));
//            System.out.println("时间999999"+dateFormat.format(date11)+"  "+dateFormat.format(date22));
//            System.out.println("获取到的值是"+enMallService.getAllTradeCount(date11,date22));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return enMallService.getAllTradeCount(date11,date22);
    }

}
